package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.*;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-29 
 * @Version: 1.0
 */

public class LC49字母异位词分组 {

    // todo 各种基本数据类型和string转换的方式
    public List<List<String>> groupAnagrams(String[] strs) {

        Map<String,List<String>> map = new HashMap<>();

        for (int i = 0; i < strs.length; i++) {

            String str = strs[i];
            char[] charArray = str.toCharArray();
            Arrays.sort(charArray);
            String s = new String(charArray);
            List<String> list = map.getOrDefault(s,new ArrayList<>());
            list.add(str);
            map.put(s,list);
        }

        List<List<String>> list = new ArrayList<>();

        for (List<String> value : map.values()) {
            list.add(value);
        }

        return list;
    }


    @Test
    public void test() {

        // 测试代码


        groupAnagrams(new String[]{"eat", "tea", "tan", "ate", "nat", "bat"});
    }

}
